<?php

/**
 * Created by PhpStorm.
 * User: tianq
 * Date: 2015-12-13
 * Time: 13:40
 */
class db_test {

    private $db;

    public function __construct() {
        $this->db = D('user');
    }

    public function insert() {
        $user = [
            'name' => 'nihao',
            'pwd' => md5("1")
        ];

        echo "insert";
        var_dump($this->db->insert($user));
    }

    public function update() {
        D('user');
        echo "update";
        $user = [
            'name' => 'nihao3dddd',
            'pwd' => md5("12")
        ];
        print_r($this->db->update($user, 'id=1001'));
        print_r($this->db->update($user, 'id=?', [1002]));
        print_r($this->db->update($user, 1003));
        print_r($this->db->get(1003));
    }

    public function delete() {
        echo "delete";
        print_r($this->db->delete('id=1000'));
        print_r($this->db->delete('id=?', [1000]));
    }

    public function get() {
        echo "get";
        print_r($this->db->get('1001', 'name'));
        print_r($this->db->get('id=?', [1001]));
    }

    public function value() {
        echo "value";
        print_r($this->db->value('1=1', 'max(id)'));
        print_r($this->db->value('id=1002'));
        print_r($this->db->value('id=?', [1002]));
        print_r($this->db->value('id=1002', 'pwd'));
    }

    public function find() {
        echo "find:";
        print_r($this->db->find('id>1000 limit 10'));
        print_r($this->db->find('id > ? limit 10', [1000]));
    }

    public function select() {
        echo "select";
        print_r($this->db->select('select * from user where id > 1000 limit 10'));
        print_r($this->db->select('select * from user where id > ? limit 10', [1000]));
    }

}